package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import negocio.Usuario;
import util.ConnectionHelper;

public class RepositorioUsuario implements IRepositorioUsuario {

	@Override
	public Usuario validarLogin(String email, String senha) {

		Statement stmt = null;
		Usuario user = null;
		String query = "select *  from" + " usuarios " + "where email = '"
				+ email + "' and senha = '" + senha	+ "'";

		try {
			Connection con = ConnectionHelper.abrir();
			stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(query);
			while (rs.next()) {
				user = new Usuario();
				String nome = rs.getString("nome");
				int id = rs.getInt("id");
				String emailUser = rs.getString("email");
				String senhaUser = rs.getString("senha");
				
				user.setNome(nome);
				user.setId(id);
				user.setEmail(emailUser);
				user.setSenha(senhaUser);
				
			}
		} catch (SQLException e) {
				e.printStackTrace();
		} finally {
			if (stmt != null) {
				try {
					stmt.close();
				} catch (SQLException e) {

					e.printStackTrace();
				}
			}
		}
		return user;

	}
}
